package org.example.liaoxuefeng.tongyilingma;

/**
 * 2. 创建接收者类 TextEditor
 *
 * @author: 默苍璃
 * @date: 2024-07-17 17:31
 */
public class TextEditor {

    StringBuilder buffer = new StringBuilder();
    private CommandHistory history = new CommandHistory();

    public void add(String text) {
        history.push(new AddCommand(this, text));
    }

    public void delete() {
        if (buffer.length() > 0) {
            history.push(new DeleteCommand(this));
        }
    }

    public void undo() {
        history.undo();
    }

    public void redo() {
        history.redo();
    }

    public String getState() {
        return buffer.toString();
    }

}

